package hr.ctg.service.work;

import java.util.Date;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.joda.time.DateTime;

@Scope(ScopeType.APPLICATION)
@Install(false)
@Name("workManager")
// @Startup
public class WorkManager {
	private String work;
	private int period;
	private int delay;
	private boolean startup;
	private String startupDepends;

	@Create
	public void create() {
		final Date d = new DateTime().plusMillis(delay).toDate();
		((Work) Component.getInstance(work)).process(d, period);
	}

	public void execute() {
		final Date d = new DateTime().plusMillis(100).toDate();
		((Work) Component.getInstance(work)).process(d);
	}

	public String getWork() {
		return work;
	}

	public void setWork(final String work) {
		this.work = work;
	}

	public int getPeriod() {
		return period;
	}

	public void setPeriod(final int period) {
		this.period = period;
	}

	public boolean isStartup() {
		return startup;
	}

	public void setStartup(final boolean startup) {
		this.startup = startup;
	}

	public String getStartupDepends() {
		return startupDepends;
	}

	public void setStartupDepends(final String startupDepends) {
		this.startupDepends = startupDepends;
	}

	public int getDelay() {
		return delay;
	}

	public void setDelay(final int delay) {
		this.delay = delay;
	}

}
